import React from 'react';
import styles from './index.less';
import _ from 'lodash';
// components
import { PageLoading, TRDefault } from '@/components';
import { fetchUrls } from './services';

// 帆软嵌套
export default function FineReport(props) {
  const menuCode = props?.match?.params?.menuCode || 'FieldRemoteService';

  const [spinning, setSpinning] = React.useState(true);
  const [urls, setUrls] = React.useState([]);

  React.useEffect(() => {
    initData();
  }, [menuCode]);

  const initData = async () => {
    setSpinning(true);
    const _urls = await fetchUrls(menuCode);
    setSpinning(false);
    setUrls(_urls);
  };

  if (spinning) return <PageLoading />;
  if (!urls.length) return <TRDefault type="lock" message="您没有相关权限,请联系管理员" />;
  return (
    <div className={styles.con}>
      {urls.map((url, idx) => (
        <iframe key={idx} src={url} />
      ))}
    </div>
  );
}
